//package cn.xinfei.xdecision.rabbit;
//
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.amqp.rabbit.connection.CorrelationData;
//import org.springframework.amqp.rabbit.core.RabbitTemplate;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
//import org.springframework.stereotype.Service;
//
//import java.util.function.BiConsumer;
//
//@Slf4j
//@Service
//@ConditionalOnProperty(name = "xdecision.rabbit.enable")
//public class RabbitMQProducer {
//
//    @Autowired
//    private RabbitTemplate rabbitTemplate;
//
//    public void send(XDecisionMessage msg, BiConsumer<CorrelationData.Confirm, Throwable> bs) {
//        CorrelationData correlationData = new CorrelationData(msg.getMsgId());
//        // 2.2.准备ConfirmCallback
//        correlationData.getFuture().addCallback(result -> {
//            // 判断结果
//            if (result.isAck()) {
//                // ACK
//                log.debug("消息成功投递到交换机！消息ID: {}", correlationData.getId());
//            } else {
//                // NACK
//                log.error("消息投递到交换机失败！消息ID：{}", correlationData.getId());
//                // 重发消息
//            }
//            bs.accept(result, null);
//        }, ex -> {
//            // 记录日志
//            log.error("消息发送失败！", ex);
//            bs.accept(null, ex);
//            // 重发消息
//        });
//
//        rabbitTemplate.convertAndSend(msg.getExchange(), msg.getQueue(), msg.getData(), correlationData);
//        log.info("消息= {},exchange={} ,queue={} 已发送 待确认", msg.getMsgId(), msg.getExchange(), msg.getQueue());
//    }
//}
